<template>
  <div class="work-modal">
    <!-- 工作集类型修改 Start -->
    <a-modal
      :title="workTypeEdit ? '修改工作集类型' : '新增工作集类型'"
      :visible="workTypeShow"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <a-form-model
        layout="horizontal"
        :model="workTypeData"
        :rules="workTypeFormRules"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 14 }"
        ref="workTypeForm"
      >
        <a-form-model-item label="类型名称" prop="JobGroupTypeName">
          <a-input allow-clear v-model="workTypeData.JobGroupTypeName" />
        </a-form-model-item>
        <a-form-model-item label="类型编码">
          <a-input allow-clear v-model="workTypeData.JobGroupTypeNo" />
        </a-form-model-item>
        <a-form-model-item label="类型描述">
          <a-textarea
            style="resize: none"
            v-model="workTypeData.JobGroupTypeDesc"
          />
        </a-form-model-item>
        <a-form-model-item label="类型备注">
          <a-textarea style="resize: none" v-model="workTypeData.Remark" />
        </a-form-model-item>
        <a-form-model-item label="业务">
          <a-select v-model="workTypeData.JobGroupClass">
            <a-select-option
              v-for="item in jobGroupClassList"
              :key="item.value"
              :value="item.value"
            >
              {{ item.label }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        
      </a-form-model>
    </a-modal>
    <!-- 工作集类型修改 End -->
  </div>
</template>
   
  <script>
import {
  addJobGroupTypeDto,
  updateJobGroupTypeDto,
} from "@/api/JobGroupType/index";
export default {
  props: ["workTypeShow", "workTypeEdit", "workTypeData"],
  data() {
    return {
      confirmLoading: false, //提交按钮Loading
      jobGroupClassList: [
        { label: "生产", value: 0 },
        { label: "质量", value: 1 },
        { label: "消毒", value: 2 },
      ], //类别列表
      workTypeFormRules: {
        JobGroupTypeName: [
          {
            required: true,
            message: "请填写类型名称",
            trigger: "blur",
            help: "",
          },
        ],
      }, //校验项
    };
  },
  methods: {
    //提交函数
    handleOk() {
      this.$refs.workTypeForm.validate(async (valid) => {
        if (valid) {
          if (this.workTypeEdit) {
            let res = await updateJobGroupTypeDto(this.workTypeData);
            res.Success
              ? this.$message.success("修改成功")
              : this.$message.error(res.Message);
            this.handleCancel();
            this.UpWorkType();
          } else {
            let res = await addJobGroupTypeDto(this.workTypeData);
            res.Success
              ? this.$message.success("新增成功")
              : this.$message.error(res.Message);
            this.handleCancel();
            this.UpWorkType();
          }
        }
      });
    },
    //关闭弹窗
    handleCancel() {
      this.closeCheck();
      this.$emit("update:workTypeShow", false);
    },
    //清除校验
    closeCheck() {
      this.$refs.workTypeForm.clearValidate();
    },
    //更新表格
    UpWorkType() {
      this.$emit("UpTypeData");
    },
  },
};
</script>
   
  <style lang = "less" scoped>
</style>